﻿
using Abp.Application.Services.Dto;
using Abp.Web.Models;
using Abp.Web.Mvc.Authorization;
using KDS.Mes.Authorization;
using KDS.Mes.Mes.ProcessTypes;
using KDS.Mes.Mes.ProcessTypes.Dtos;
using KDS.Mes.Web.Models.ProcessTypes;
using System;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace KDS.Mes.Web.Controllers
{
    public class ProcessTypesController : MesControllerBase
    {

        private readonly IProcessTypeAppService _processTypeAppService;

        public ProcessTypesController(IProcessTypeAppService processTypeAppService)
        {
            _processTypeAppService = processTypeAppService;
           
        }

        public  ActionResult Index()
        {
		   //var model = new GetProcessTypeInput {FilterText = Request.QueryString["filterText"]};
            return View();
        }

        [DontWrapResult]
        public JsonResult GetAllProcessTypes(int limit, int offset, string sortfiled, string sortway)
        {
            var sort = !string.IsNullOrEmpty(sortfiled) ? string.Format("{0} {1}", sortfiled, sortway) : "";
            var filter = new GetProcessTypeInput
            {
                SkipCount = offset,
                MaxResultCount = limit,
                Sorting = sort,
            };
            var pagedTasks = _processTypeAppService.GetPagedProcessTypes(filter);
            return Json(new { total = pagedTasks.TotalCount, rows = pagedTasks.Items }, JsonRequestBehavior.AllowGet);
        }



        /// <summary>
        /// 根据id获取进行编辑或者添加的用户信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [AbpMvcAuthorize(AppPermissions.Pages_Bom_ProcessTypes_Create, AppPermissions.Pages_Bom_ProcessTypes_Edit)]
        public async Task<PartialViewResult> CreateOrEditProcessTypeModal(int? id)
        {
		var input=new NullableIdDto<int>{Id=id};
	 
                 var output=    await _processTypeAppService.GetProcessTypeForEditAsync(input);

				 var viewModel=new CreateOrEditProcessTypeModalViewModel(output);


            return PartialView("_CreateOrEditProcessTypeModal",viewModel);
        }
	 
       
    }
}